<?php
/*
 * 用户中心
 */
namespace Mobile\Controller;

class ZhengshuController extends BaseController {
    
    
    public function __construct() {
        parent::__construct();

    }
    
    /*
     * 授权证书
     */
    public function index(){
    
       
        if(get('uid')){
            $this->uid = get('uid');
            $this->memberinfo = $this->getMemberInfobyUid($this->uid);
        }
        
            
        $seo_data = array(
            "title" => '授权证书-'.C('SITE_NAME'),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
    
        $share_data = array(
            "title" => '授权证书-'.C('SITE_NAME'),
            //     "url" => '/mobile/user/zhengshu?zsuid='.$this->uid,
        );
        $this->setShare($share_data);
        if($this->memberinfo['grade_id']<=1){
            //$this->error2('您暂时还不是总代','/mobile/');exit;
        }
        $realname = $this->memberinfo['realname'];
        if(!$realname){
            header("Location:/mobile/zhengshu/myinfo");exit;
          //  $this->error2('请先填写真实姓名',"/mobile/zhengshu/myinfo");exit;
        }
        $memberinfo = $this->getMemberInfobyUid($this->uid);
        $grade_id = $memberinfo['grade_id'];
        $realname = $memberinfo['realname'];
        $background_url = C("UPYUN_DOMAIN").C("ZHENGSHU_".$grade_id);
        
        $background_url .= '!/fw/641/watermark/size/35';
        $background_url .= "/text/".base64url($realname);
        if($grade_id==6){
            $background_url .= "/color/FFFFFF";
        }else{
            $background_url .= "/color/000000";
        }
        $background_url .= "/margin/233x465";
        
        
        $background_url .= '/watermark/size/35';
        $background_url .= "/text/".base64url($this->uid);
        if($grade_id==6){
            $background_url .= "/color/FFFFFF";
        }else{
            $background_url .= "/color/000000";
        }
        $background_url .= "/margin/200x510";
        
        $bianhao = "LLJ".date("Y").sprintf("%05d",$this->uid);
        $background_url .= '/watermark/size/35';
        $background_url .= "/text/".base64url($bianhao);
        if($grade_id==6){
            $background_url .= "/color/FFFFFF";
        }else{
            $background_url .= "/color/000000";
        }
        $background_url .= "/margin/303x556";
        
        if($uid) {
            header('Location: '.$background_url);
        }
        
        $this->assign('zhengshu',$background_url);
        
        $this->display();
    }
    
    
    /*
     *
     */
    public function zs(){
        
        $uid = get('zsuid');
        
        $memberinfo = $this->getMemberInfobyUid($uid);
        
        $grade_id = $memberinfo['grade_id'];
        
        $realname = $memberinfo['realname'];
        
        
        if($grade_id<=2){
            $this->error2('您暂时还不是总代');exit;
        }
        
        if(!$realname){
            $this->error2('请先填写真实姓名');exit;
        }
        
        $bianhao = "AIDU".date("Y").sprintf("%05d",$uid);

        $background_url = C("UPYUN_DOMAIN").C("ZHENGSHU_".$grade_id);
        
        $read_backgroud = file_get_contents($background_url);//读取底图

        $background = imagecreatefromstring($read_backgroud);//把底图载入画板
        
        $font = ROOT.'/Static/mobile/font/fzkt.ttf';//思源黑体
        
        $color= imagecolorallocate($background,0,0,0);//颜色
        imagettftext($background,12,0,154,313,$color, $font,$realname);//把名字写上去
        //imagettftext($background,18,0,430,360,$color, $font,$uid);//把uid写上去
        imagettftext($background,12,0,200,435,$color, $font,$bianhao);
        
        
        $file = ROOT.'/upload/zs/'.$uid."_".$grade_id.".jpg";//存储的文件名

        imagejpeg($background,$file,100);//最后一个参数是图片质量,保存图片到文件

        $background = file_get_contents($file);
        
        header("Content-Type: image/jpeg");
        echo $background;exit;
    }
    
    
    /*
     * 提示关注
     */
    public function subscribe(){
    
        $seo_data = array(
            "title" => "关注".C("STIE_NAME"),
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
    
        $share_data = array(
            "title" => "关注".C("STIE_NAME"),
        );
        $this->setShare($share_data);
        $this->display();
    }
    
    
    /*
     * 修改资料
     */
    public function myinfo(){
    
        //判断是否有关注公众号,如果没有,先提示关注公众号
        if(!$this->memberinfo['subscribe']){
            $this->redirect('/mobile/zhengshu/subscribe');exit;
        }
    
        if($this->memberinfo['grade_id']<=1){
            $this->error2('您暂时还不是省代及以上代理,请先购买成为代理','/mobile/');exit;
        }
    
        if($this->memberinfo['realname']){
            $this->redirect('/mobile/zhengshu/');exit;
        }
    
        //更新信息
        if(IS_AJAX){
    
            $allow = array(
                "realname","mobile","wechat_id","idcard"
            );
            $must = array("realname","mobile");
            $data = param_filter($_POST, $allow,$must,true,true);
    
            if(empty($data)){
                return_json(1,"请检查信息是否填写完整");
            }
            //检查手机号
            if(!check_mobile($data['mobile'])){
                return_json(1,"手机号填写错误");
            }
    
    
            //更新用户信息
            $res = $this->updateMemberInfoByUid($this->uid, $data);
            if($res !== false){
                return_json(0,"更新成功","","/mobile/zhengshu");
            }
            return_json(1,"系统错误,编辑失败");
        }
    
    
        $seo_data = array(
            "title" => "完善资料后获取证书",
            "description" => "",
            "keywords" => "",
        );
        $this->setSeo($seo_data);
    
        $share_data = array(
            "title" => $this->lang['user_myinfo'],
        );
        $this->setShare($share_data);
    
        $this->display();
    }
    
    
    
    
}